Technical Q&A QA1282
Using a QuickTime time base callback to detect when a movie has stopped


Q: I'm trying to use NewCallBack with callBackAtExtremes and triggerAtStop to detect when a Movie has stopped playing, but the QuickTime documentation doesn't say where to specifically set these flags. Depending on what flags I do use, NewCallBack sometimes returns NULL. How do you set up a callback function using callBackAtExtremes and triggerAtStop?

A: triggerAtStop is a flag passed to the CallMeWhen API as the param1 parameter when callBackAtExtremes was used as the cbType flag to NewCallBack. Listing 1 demonstrates how to set this up.

Listing 1.

// A generic callback function, installed by CallMeWhen.

// pascal void MyQTCallBackProc(QTCallBack cb, long refCon);



pascal void MyDoSomethingCallBack(QTCallBack cb, long refCon)

{

    MyAppDataPtr myStuff;



    if (NULL == refCon) return;

    myStuff = (MyAppDataPtr)refCon;

    myStuff->didSomething = true;



    return;

}



// Setting up a CallBack to fire using the callBackAtExtremes and

// triggerAtStop flags.

// MyDoSomethingCallBack function will be called when the time

// base has stopped.



OSErr SetUpTriggerAtStopCallBack(MyAppDataPtr inAppData)

{

    QTCallBack    theQTCallBack;

    QTCallBackUPP theCallBackUPP;


    OSErr err = paramErr;



    theQTCallBack = NewCallBack(GetMovieTimeBase(inAppData->myMovie),

                                callBackAtExtremes);

    if (theQTCallBack) {

        theCallBackUPP = NewQTCallBackUPP(MyDoSomethingCallBack);

        err = CallMeWhen(theQTCallBack, theCallBackUPP,

                         inAppData, triggerAtStop, 0, 0);

    }



    // save these so we can toss them later

    inAppData->myQTCallBack = theQTCallBack;

    inAppData->myCallBackUPP = theCallBackUPP;

    return err;

}

When done with the QTCallBack and QTCallBackUPP, remember to call DisposeCallBack and DisposeQTCallBackUPP.

References:


[Aug 12, 2003]


Developer Documentation | Technical Notes | Development Kits | Sample Code